home *** CD-ROM | disk | FTP | other *** search
/ Freelog 67 / Freelog067.iso / Nouveautés / Httract / httrack-3.33.exe / {app} / libtest / example.c next >
C/C++ Source or Header  |  2002-11-11  |  4KB  |  159 lines

  1. /*
  2.     HTTrack library example
  3.     .c file
  4.  
  5.     To Build on Windows:
  6.     - install winhttrack
  7.     - set the proper path in the project settings (especially for the httrack lib and dll)
  8.     - compile in multithreaded DLL
  9.     - avoid precompiled headers with VC
  10.  
  11.     To Build on Linux:
  12.     - install httrack
  13.     - link with libhttrack.so and compile using something like:
  14.       gcc example.c -I/usr/include/httrack -lhttrack
  15. */
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. #include "httrack-library.h"
  23.  
  24. #include "example.h"
  25.  
  26.  
  27.  
  28. /*
  29.  * Name:           main
  30.  * Description:    main() function
  31.  * Parameters:     None
  32.  * Should return:  error status
  33. */
  34. int main(void) {
  35.   /* 
  36.      First, ask for an URL 
  37.      Note: For the test, option r2 (mirror max depth=1) and --testscan (no index, no cache, do not store, no log files)
  38.   */
  39.   char _argv[][256] = {"httrack_test" , "<URL>" , "-r3" , "--testscan" , ""  };
  40.   char* argv[]      = {NULL           , NULL    , NULL  , NULL        , NULL};
  41.   int         argc = 0;
  42.   while(strlen(_argv[argc])) {
  43.     argv[argc]=_argv[argc];
  44.     argc++;
  45.   }
  46.   argv[argc]=NULL;
  47.   printf("HTTrackLib test program\n");
  48.   printf("Enter URL (example: www.foobar.com/index.html) :");
  49.   scanf("%s",argv[1]);
  50.   printf("Test: 1 depth\n");
  51.  
  52.   hts_init();
  53.   htswrap_add("init",httrack_wrapper_init);
  54.   htswrap_add("free",httrack_wrapper_uninit);
  55.   htswrap_add("start",httrack_wrapper_start);
  56.   htswrap_add("change-options",httrack_wrapper_chopt);
  57.   htswrap_add("end",httrack_wrapper_end);
  58.   htswrap_add("check-html",httrack_wrapper_checkhtml);
  59.   htswrap_add("loop",httrack_wrapper_loop);
  60.   htswrap_add("query",httrack_wrapper_query);
  61.   htswrap_add("query2",httrack_wrapper_query2);
  62.   htswrap_add("query3",httrack_wrapper_query3);
  63.   htswrap_add("check-link",httrack_wrapper_check);
  64.   htswrap_add("pause",httrack_wrapper_pause);
  65.   htswrap_add("save-file",httrack_wrapper_filesave);
  66.   htswrap_add("link-detected",httrack_wrapper_linkdetected);
  67.   htswrap_add("transfer-status",httrack_wrapper_xfrstatus);
  68.  
  69.   /* Then, launch the mirror */
  70.   hts_main(argc,argv);
  71.  
  72.   /* Wait for a key */
  73.   printf("\nPress ENTER key to exit\n");
  74.   scanf("%s",argv[1]);
  75.  
  76.   /* That's all! */
  77.   return 0;
  78. }
  79.  
  80.  
  81. /* CALLBACK FUNCTIONS */
  82.  
  83. /* Initialize the Winsock */
  84. void CDECL httrack_wrapper_init(void) {
  85.   printf("Engine started\n");
  86. #ifdef _WIN32
  87.   {
  88.     WORD   wVersionRequested;   // requested version WinSock API
  89.     WSADATA wsadata;            // Windows Sockets API data
  90.     int stat;
  91.     wVersionRequested = 0x0101;
  92.     stat = WSAStartup( wVersionRequested, &wsadata );
  93.     if (stat != 0) {
  94.       printf("Winsock not found!\n");
  95.       return;
  96.     } else if (LOBYTE(wsadata.wVersion) != 1  && HIBYTE(wsadata.wVersion) != 1) {
  97.       printf("WINSOCK.DLL does not support version 1.1\n");
  98.       WSACleanup();
  99.       return;
  100.     }
  101.   }
  102. #endif
  103.  
  104. }
  105. void CDECL httrack_wrapper_uninit(void) {
  106.   printf("Engine exited\n");
  107. #ifdef _WIN32
  108.   WSACleanup();
  109. #endif
  110. }
  111. int CDECL httrack_wrapper_start(httrackp* opt) {
  112.   printf("Start of mirror\n");
  113.   return 1; 
  114. }
  115. int CDECL httrack_wrapper_chopt(httrackp* opt) {
  116.   return CDECL httrack_wrapper_start(opt);
  117. }
  118. int  CDECL httrack_wrapper_end(void) { 
  119.   printf("End of mirror\n");
  120.   return 1; 
  121. }
  122. int CDECL httrack_wrapper_checkhtml(char* html,int len,char* url_adresse,char* url_fichier) {
  123.   printf("Parsing html file: http://%s%s\n",url_adresse,url_fichier);
  124.   return 1;
  125. }
  126. int CDECL httrack_wrapper_loop(void* _back,int back_max,int back_index,int lien_n,int lien_tot,int stat_time,hts_stat_struct* stats) {
  127.   /* printf("..httrack_wrapper_loop called\n"); */
  128.   return 1;
  129. }
  130. char* CDECL httrack_wrapper_query(char* question) {
  131.   /* Answer is No */
  132.   return "N";
  133. }
  134. char* CDECL httrack_wrapper_query2(char* question) {
  135.   /* Answer is No */
  136.   return "N";
  137. }
  138. char* CDECL httrack_wrapper_query3(char* question) {
  139.   /* Answer is "" */
  140.   return "";
  141. }
  142. int CDECL httrack_wrapper_check(char* adr,char* fil,int status) {
  143.   printf("Link status tested: http://%s%s\n",adr,fil);
  144.   return -1;
  145. }
  146. void CDECL httrack_wrapper_pause(char* lockfile) {
  147.   /* Wait until lockfile is removed.. */
  148. }
  149. void CDECL httrack_wrapper_filesave(char* file) {
  150. }
  151. int CDECL httrack_wrapper_linkdetected(char* link) {
  152.   printf("Link detected: %s\n",link);
  153.   return 1;
  154. }
  155. int CDECL httrack_wrapper_xfrstatus(void* back) {
  156.   return 1;
  157. }
  158.  
  159.